<template>
  <div class="sec_kill" v-if="secKillData.length">
    <p class="sec_kill_title" @click="goSeckillListPage(activeIndex)">
      查看全部<em></em>
    </p>
    <van-tabs
      v-model="activeIndex"
      :ellipsis="false"
      background="linear-gradient(
    95deg,
    rgba(249, 28, 49, 1) 0%,
    rgba(233, 9, 32, 1) 100%"
      title-active-color="#fff"
      class="listlong"
      :class="{
        listLess2: secKillNavData.length == 3,
        listLess3: secKillNavData.length > 3
      }"
      @click="onClick"
    >
      <van-tab v-for="(v, index) in secKillNavData" :key="index">
        <div slot="title">
          <p class="time">{{ v.timeStr }}</p>
          <p class="text" v-if="v.status === 1">已开抢</p>
          <p class="text" v-if="v.status === 2">抢购中</p>
          <p class="text" v-if="v.status === 3">即将开始</p>
        </div>
        <!-- 内容 {{ index }} -->
        <ul class="time_show_con" ref="imgscroll">
          <li
            class="time_show_single j_akc_ubt"
            v-for="(v, index) in secKillListData[activeIndex]"
            :key="index"
            @click="goSeckillList(v, index)"
          >
            <img class="seckill_img" :src="v.productPicUrlImg" />
            <p class="seckill_name">{{ v.brandName }}</p>
            <p class="seckill_price">
              ¥{{ v.price / 100 }}<span>¥{{ v.tagPrice / 100 }}</span>
            </p>
          </li>
          <li class="more" @click="goSeckillListPage(activeIndex)">
            <div><span>查看全部</span><i class="item_pro_more"></i></div>
          </li>
        </ul>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
export default {
  name: '',
  props: {
    secKillData: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      secKillListData: [],
      secKillNavData: [],
      activeIndex: 0
    };
  },

  mounted() {
    console.log('secKillNavData', this.secKillData.length);
    const secKillNavData = [];
    const secKillListData = [];
    this.secKillData.forEach((ele, index) => {
      secKillNavData.push({
        timeStr: ele.timeStr,
        status: ele.status,
        selectFlag: ele.selectFlag,
        index
      });
      if (ele.selectFlag === 1) {
        this.activeIndex = index;
        console.log('this.activeIndex', this.activeIndex);
      }
      secKillListData.push(ele.productList);
    });
    this.secKillNavData = secKillNavData || [];
    this.secKillListData = secKillListData || [];
    this.secKillListData.forEach(v => {
      v = v || [];
      v.forEach(ele => {
        const productPicUrlImg = ele.pictureUrls.split(',')[0];
        ele.productPicUrlImg = productPicUrlImg;
      });
    });
  },
  computed: {},
  methods: {
    // 点击table
    onClick(name) {
      console.log(name);
    },
    // 去秒杀列表页
    goSeckillListPage(v) {
      console.log(v);
    },
    // 去商品详情页
    goSeckillList(v) {
      console.log(v);
    }
  }
};
</script>
<style>
.listlong.van-tabs--line {
  bottom: 0 !important;
  box-sizing: border-box;
  padding-top: 40px;
}
.listlong .van-tabs__nav--line {
  padding-bottom: 0 !important;
  width: 100%;
  box-sizing: border-box;
}
.listlong.van-tabs--line .van-tabs__wrap {
  height: 40px !important;
  /* padding: 0 7px; */
}
.listlong .van-tab {
  z-index: 2;
  color: rgba(255, 255, 255, 0.6);
  font-size: 15px;
  padding: 0;
}
.listlong .van-tabs__line {
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(255, 191, 51, 1) 0%,
    rgba(255, 104, 20, 1) 100%
  ) !important;

  border-radius: 6px;
  bottom: 0;
}
.listlong.listLess2 .van-tabs__line {
  width: 25% !important;
  left: -4.5%;
}
.listlong.listLess3 .van-tabs__line {
  width: 20% !important;
  left: -4.5%;
}
.listlong .van-hairline--top-bottom::after {
  border-width: 0;
}
</style>
<style lang="scss" scoped>
.time {
  font-size: 15px;
  font-family: PingFangSC, sans-serif;
  font-weight: 500;
  padding-top: 2px;
  line-height: 21px;
}
.text {
  font-size: 11px;
  font-family: PingFangSC, sans-serif;
  font-weight: 400;
  line-height: 16px;
  padding-bottom: 4px;
  margin-top: -2px;
}
.sec_kill {
  width: 100%;
  .sec_kill_title {
    width: 100%;
    padding: 11px 11px 8px 12px;
    box-sizing: border-box;
    background-image: url('../../../../assets/promotion/sec_kill_title.png');
    background-repeat: no-repeat;
    background-size: 70px 16px;
    background-position: 12px 12px;
    color: #ffd7aa;
    font-size: 12px;
    text-align: right;
    line-height: 17px;
    em {
      width: 5px;
      height: 10px;
      margin-left: 3px;
      display: inline-block;
      background: url('../../../../assets/promotion/gold_arrow_right.png')
        no-repeat right center / 100%;
    }
  }
  .time_show_con {
    background: #fff;
    white-space: nowrap;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    text-align: left;
    height: 155px;
    padding: 12px 4px 8px 12px;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch; /* 用于 ios5+ */
    li {
      overflow: hidden;
      margin-right: 8px;
      display: inline-block;
      width: 100px;
      height: 135px;
      .seckill_img {
        width: 100px;
        height: 100px;
        display: block;
        margin-bottom: 3px;
        border-radius: 6px;
        background: pink;
      }
      .seckill_name {
        color: #333333;
        font-size: 11px;
        width: 100px;
        line-height: 16px;
        margin-bottom: 1px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .seckill_price {
        color: #e62525;
        font-size: 13px;
        font-family: PingFangSC, sans-serif;
        font-weight: 500;
        span {
          text-decoration: line-through;
          color: #999999;
          font-size: 11px;
          margin-left: 5px;
          font-weight: 400;
        }
      }
    }

    .more {
      text-align: center;
      background: #f7f7f7;
      color: #999999;
      font-size: 11px;
      vertical-align: top;
      position: relative;
      div {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        line-height: 28px;
        margin-top: 49px;
        span {
          margin-bottom: 3px;
          display: block;
        }
        .item_pro_more {
          width: 14px;
          height: 14px;
          background: url('../../../../assets/promotion/item_pro_more.png')
            no-repeat left center / 14px 14px;
          display: block;
          margin: 0 auto;
        }
      }
    }
  }
}
</style>
